<template>
  <div class="share_bonus">
    <c-title :text="'分红记录'"></c-title>
    <header class="header">
      <span>累计金额：</span><span class="price">￥{{ amount }}</span>
    </header>
    <main class="main">
      <div class="content-wrapper" v-for="item in list" :key="item.id">
        <div class="left">
          <div>订单编号:{{ item.order_sn }}</div>
          <div>时间{{ item.created_at }}</div>
        </div>
        <div class="right price">￥{{ item.amount }}</div>
      </div>
    </main>
  </div>
</template>

<script>
import {scrollMixin} from "@/utils/mixin";
export default {
  mixins: [scrollMixin],
  activated() {
    if (this.$route.params.order_type == "lawyer") {
      this.httpUrl = "plugin.lawyer-platform.frontend.controllers.dividend.getLawyer";
    } else {
      this.httpUrl = "plugin.lawyer-platform.frontend.controllers.dividend.getLawyerFirm";
    }
    this.getData();
  },
  data() {
    return {
      list: [],
      page: 1,
      last_page: 1,
      httpUrl: "",
      amount: "",
      isLoadMore: true
    };
  },
  methods: {
    getMoreData() {
      this.isLoadMore = false;
      if (this.page >= this.last_page) {
        return false;
      } else {
        let page = this.page+1;
        $http.post(this.httpUrl,{page}).then(res => {
          this.isLoadMore = true;
          if (res.result == 1) {
            this.list = this.list.concat(res.data.list.data);
            this.last_page = res.data.list.last_page;
            this.page = page;
          }
        });
      }
    },
    init(){
      this.page = 1;
      this.last_page=1;
      this.isLoadMore = true;
      this.list = [];
      this.amount = "";
    },
    getData() {
      this.init()
      $http.post(this.httpUrl).then(res => {
        if (res.result == 1) {
          this.amount = res.data.amount_total;
          this.list = res.data.list.data;
          this.last_page = res.data.list.last_page;
        }else{
          this.$toast(res.msg)
        }
      });
    }
  }
};
</script>

<style scoped lang="scss">
.price {
  color: #f13f3f;
}

.header {
  text-align: left;
  padding: 1rem;
  background: #fff;
}

.main {
  margin-top: 1rem;
}

.content-wrapper {
  display: flex;
  justify-content: space-between;
  padding: 1rem;
  background: #fff;
}

.left {
  text-align: left;
}
</style>
